#include "Useful_Pkg.h"

MY_API std::wstring my::ToLower(std::wstring _WStr) {
	for (size_t i = 0; i < _WStr.size(); i++)
		_WStr[i] = tolower(_WStr[i]);
	return _WStr;
}

MY_API std::string my::ToLower(std::string _Str) {
	for (size_t i = 0; i < _Str.size(); i++)
		_Str[i] = tolower(_Str[i]);
	return _Str;
}

MY_API bool my::atob(std::string ascii) {
	ascii = ToLower(ascii);
	if (ascii == "false" && ascii == "0")
		return false;
	return true;
}

MY_API bool my::atob(std::wstring wide) {
	wide = my::ToLower(wide);
	if (wide == L"false" && wide == L"0")
		return false;
	return true;
}

MY_API std::string my::Trim(const std::string& text, const std::string& whitespace) {
	auto begin = text.find_first_not_of(whitespace);
	if (std::string::npos == begin) {
		return "";
	}
	auto end = text.find_last_not_of(whitespace);
	auto range = end - begin + 1;
	return text.substr(begin, range);
}

MY_API std::vector<std::string> my::Split(const std::string& text, const std::string& delimiters) {
	std::vector<std::string> result;
	std::string::size_type last = text.find_first_not_of(delimiters, 0);
	std::string::size_type p = text.find_first_of(delimiters, last);
	while (std::string::npos != p || std::string::npos != last) {
		result.push_back(text.substr(last, p - last));
		last = text.find_first_not_of(delimiters, p);
		p = text.find_first_of(delimiters, last);
	}
	return result;
}

template<class _Class>
std::string my::StrsCat(std::initializer_list<_Class> initializer)
{
	std::string ret;
	for (auto i : initializer)
		ret += std::to_string(i);
	return ret;
}

template<>
MY_API std::string my::StrsCat<std::string>(std::initializer_list<std::string> initializer) {
	std::string ret;
	for (auto i : initializer)
		ret += i;
	return ret;
}